<?php
//保存配置
function C($key,$value=null){
    static $_config = array();
    $args = func_num_args();
    if($args == 1){
        if(is_string($key)){  //如果传入的key是字符串
            return isset($_config[$key])?$_config[$key]:null;
        }
        if(is_array($key)){
            if(array_keys($key) !== range(0, count($key) - 1)){  //如果传入的key是关联数组
                $_config = array_merge($_config, $key);
            }else{
                $ret = array();
                foreach ($key as $k) {
                    $ret[$k] = isset($_config[$k])?$_config[$k]:null;
                }
                return $ret;
            }
        }
    }else{
        if(is_string($key)){
            $_config[$key] = $value;
        }else{
            halt('传入参数不正确');
        }
    }
    return null;
}
//引入文件
function includeIfExist($path){
    if(file_exists($path)){
        include $path;
    }
}
//检查数据库联通性
function checkDbConnection(){
        if(file_exists(__ROOT__.'config.php')){
        $config= include 'config.php';
        C($config);
        $conn = @mysql_connect(C('DB_HOST'),C('DB_USER'),C('DB_PWD'));
        if($conn){
            return true;
        }else{
            return false;
        }
    }else{
        return false;
    }
}
?>